package pers.qianyu.module.security.schedule;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;
import pers.qianyu.module.core.domain.system.entity.SysResourcePO;
import pers.qianyu.module.security.enums.ResourceTypeEnums;
import pers.qianyu.module.security.util.SecurityUtil;
import pers.qianyu.module.system.dao.SysResourceDao;

import java.util.List;
import java.util.Objects;

/**
 * @author mizzle rain
 * @date 2021-05-03 21:38
 */
@Component
public class InitResourceTask implements CommandLineRunner {
    @Autowired
    private SysResourceDao sysResourceDao;

    @Override
    public void run(String... args) throws Exception {
        List<SysResourcePO> sysResourcePOS = sysResourceDao.selectList(null);
        for (SysResourcePO sysResourcePO : sysResourcePOS) {
            if (Objects.equals(sysResourcePO.getStatus(), ResourceTypeEnums.NEED.getCode())) {
                SecurityUtil.ACL.add(sysResourcePO);
            }
        }
    }
}
